package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	s := "hello"
	fmt.Printf("s=%s, len=%d\n", s, len(s))
	s = "你好"
	fmt.Printf("s=%s, len=%d, charLen=%d\n", s, len(s), utf8.RuneCountInString(s))
	// 字符串转字节切片
	bytes := []byte(s)
	for idx, val := range bytes {
		fmt.Printf("idx=%d, val=%s\n", idx, string(val))
	}
	fmt.Println("==================")
	//字符串转字符切片
	runes := []rune(s)
	for idx, val := range runes {
		fmt.Printf("idx=%d, val=%c\n", idx, val)
	}
	fmt.Println("===================")
	for idx, val := range s {	//按字符遍历
		fmt.Printf("idx=%d, val=%c\n", idx, val)
	}
}
